package org.budo.dubbo.protocol.dubbo;

import java.lang.reflect.Field;

import org.budo.support.lang.util.ReflectUtil;

import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;

/**
 * 改进实现版本, 加了一处空值判断
 * 
 * @author lmw
 */
public class BudoDubboProtocol extends AbstractBudoDubboProtocol {
    /**
     * BudoDubboProtocol
     */
    public BudoDubboProtocol() {
        synchronized (BudoDubboProtocol.class) {
            Field field = ReflectUtil.getField(DubboProtocol.class, "INSTANCE");
            ReflectUtil.setFieldValue(null, field, this); // 设置 DubboProtocol.INSTANCE 静态属性的值为 BudoDubboProtocol 的实例,
        }
    }

    /**
     * 改进实现版本, 加了空值判断
     * 
     * @see com.alibaba.dubbo.rpc.protocol.dubbo.CallbackServiceCodec#decodeInvocationArgument(Channel, RpcInvocation, Class<?>[], int, Object)
     */
    protected Invoker<?> getInvoker(Channel channel, Invocation invocation) throws RemotingException {
        return super.doGetInvokerNew(channel, invocation);
    }
}